package com.example.arithmeticleetcode.leetcode.dec;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-12-28 09:22
 **/
public class Demo27 {

    public int eatenApples(int[] apples, int[] days) {
        int sum = 0;
        int sum2 = 0;
        for (int i = 0; i < apples.length; i++) {
            if (apples[i] == 0 && days[i] == 0) continue;
            if (apples[i] != 0 && days[i] == 0) {
                sum2 += apples[i];
                continue;
            }
            int min = Math.min(apples[i], days[i]);
            if (i == 0) sum += min;
            else if (sum < min) sum += min;
        }
        System.out.println();
        return sum + sum2;
    }
}
